﻿class MdTable {
    registerTableScrollEvent(e) {
        e.registerScrollEvent = () => {
            this.SetScrollPositionClassName(e);
        }

        setTimeout(() => {
            e && e.registerScrollEvent();
        }, 500);

        e.addEventListener && e.addEventListener('scroll', e.registerScrollEvent);

        //const t = e.scrollWidth
        //    , n = e.clientWidth
        //    , o = e.scrollLeft
        //    , r = e.parentElement.classList.contains("m-data-table--rtl");
        //Math.abs(t - ((r ? -o : o) + n)) < 1 ? (e.classList.remove("scrolling"),
        //    e.classList.remove("scrolled-to-left"),
        //    e.classList.add("scrolled-to-right")) : Math.abs(o - (r ? t - n : 0)) < 1 ? (e.classList.remove("scrolling"),
        //        e.classList.remove("scrolled-to-right"),
        //        e.classList.add("scrolled-to-left")) : (e.classList.remove("scrolled-to-right"),
        //            e.classList.remove("scrolled-to-left"),
        //            e.classList.add("scrolling"))
    }
    cancelTableScrollEvent(e) {
        if (e) {
            e.removeEventListener && e.removeEventListener('scroll', e.registerScrollEvent);
        }
    }
    SetScrollPositionClassName(e) {
        const scrollLeft = e.scrollLeft;
        const scrollWidth = e.scrollWidth;
        const clientWidth = e.clientWidth;

        let pingLeft = false;
        let pingRight = false;

        if ((scrollWidth == clientWidth && scrollWidth != 0)) {
            pingLeft = false;
            pingRight = false;
        }
        else if (scrollLeft == 0) {
            pingLeft = false;
            pingRight = true;
        }
        else if (Math.abs(scrollWidth - (scrollLeft + clientWidth)) <= 1) {
            pingRight = false;
            pingLeft = true;
        }
        else {
            pingLeft = true;
            pingRight = true;
        }

        pingLeft ? e.classList.add("md-table-container-ping-left") : e.classList.remove("md-table-container-ping-left");
        pingRight ? e.classList.add("md-table-container-ping-right") : e.classList.remove("md-table-container-ping-right");
    }
}
window.mdTable = new MdTable();